Don't pull in dev-deps for `cargo build`
authorAlex Crichton <alex@alexcrichton.com>
Mon, 11 Aug 2014 04:36:29 +0000 (21:36 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 11 Aug 2014 04:40:58 +0000 (21:40 -0700)
Also don't pull them in for `cargo doc`, but continue to pull them in for
`cargo run` and `cargo test`.

Closes #351

src/bin/cargo-build.rs
src/bin/cargo-doc.rs
src/bin/cargo-run.rs
src/bin/cargo-test.rs
src/cargo/ops/cargo_compile.rs
tests/test_cargo_compile_path_deps.rs

index 7261a20df9efc34946c4d8635b53d2a3867a2695..4d20e607db133e58d449f8982ca0015507e58a72 100644 (file)
@@ -54,6 +54,7 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
         shell: shell,
         jobs: options.flag_jobs,
         target: options.flag_target.as_ref().map(|t| t.as_slice()),
+        dev_deps: false,
     };
 
     ops::compile(&root, &mut opts).map(|_| None).map_err(|err| {
index 158db18b89e049c2c408776eb0c40cc54ca55787..a59b3d35a21856baa31a1b647827491cb40ed681 100644 (file)
@@ -47,6 +47,7 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
             shell: shell,
             jobs: options.flag_jobs,
             target: None,
+            dev_deps: false,
         },
     };
 
index 546e793c52cfc32fd962f346cba9674607b31117..510027cdaba57845d1d394681ced04e3c39a45c6 100644 (file)
@@ -44,6 +44,7 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
         shell: shell,
         jobs: options.flag_jobs,
         target: None,
+        dev_deps: true,
     };
 
     let err = try!(ops::run(&root, &mut compile_opts,
index cd3628dbefa45fe9b79e489332c29a19b86bca73..cd1ce0e970bd6858ec05ccfc73293ca33c426391 100644 (file)
@@ -46,6 +46,7 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
         shell: shell,
         jobs: options.flag_jobs,
         target: options.flag_target.as_ref().map(|s| s.as_slice()),
+        dev_deps: true,
     };
 
     let err = try!(ops::run_tests(&root, &mut compile_opts,
index 921bf584169c672ee4c88c65026afcb8231657b6..44d9afb49f0fdf3c24a8e8692998df8971151d97 100644 (file)
@@ -42,12 +42,14 @@ pub struct CompileOptions<'a> {
     pub shell: &'a mut MultiShell,
     pub jobs: Option<uint>,
     pub target: Option<&'a str>,
+    pub dev_deps: bool,
 }
 
 pub fn compile(manifest_path: &Path,
                options: &mut CompileOptions)
                -> CargoResult<ops::Compilation> {
-    let CompileOptions { update, env, ref mut shell, jobs, target } = *options;
+    let CompileOptions { update, env, ref mut shell, jobs, target,
+                         dev_deps } = *options;
     let target = target.map(|s| s.to_string());
 
     log!(4, "compile; manifest-path={}", manifest_path.display());
@@ -79,6 +81,9 @@ pub fn compile(manifest_path: &Path,
 
         let mut config = try!(Config::new(*shell, jobs, target.clone()));
         let mut registry = PackageRegistry::new(&mut config);
+        let dependencies = package.get_dependencies().iter().filter(|dep| {
+            dep.is_transitive() || dev_deps
+        }).map(|d| d.clone()).collect::<Vec<_>>();
 
         match try!(ops::load_lockfile(&lockfile, source_id)) {
             Some(r) => try!(add_lockfile_sources(&mut registry, &package, &r)),
@@ -86,13 +91,13 @@ pub fn compile(manifest_path: &Path,
         }
 
         let resolved = try!(resolver::resolve(package.get_package_id(),
-                                              package.get_dependencies(),
+                                              dependencies.as_slice(),
                                               &mut registry));
 
         try!(registry.add_overrides(override_ids));
         let resolved_with_overrides =
                 try!(resolver::resolve(package.get_package_id(),
-                                       package.get_dependencies(),
+                                       dependencies.as_slice(),
                                        &mut registry));
 
         let req: Vec<PackageId> = resolved_with_overrides.iter().map(|r| {
index 39cf9cdbba6e554b136c2544636cb8e9991e4c5d..b05e468e10333f8790c50e9e11d06b5aaa6a8529 100644 (file)
@@ -1,7 +1,7 @@
 use std::io::File;
 
 use support::{ResultTest, project, execs, main_file, cargo_dir, path2url};
-use support::{COMPILING, FRESH};
+use support::{COMPILING, FRESH, RUNNING};
 use support::paths::PathExt;
 use hamcrest::{assert_that, existing_file};
 use cargo;
@@ -120,16 +120,54 @@ test!(cargo_compile_with_root_dev_deps {
 
     p2.build();
     assert_that(p.cargo_process("cargo-build"),
-        execs().with_stdout(format!("{} bar v0.5.0 ({})\n\
-                                     {} foo v0.5.0 ({})\n",
-                                    COMPILING, p.url(),
-                                    COMPILING, p.url())));
+                execs().with_status(101))
+})
 
-    assert_that(&p.bin("foo"), existing_file());
+test!(cargo_compile_with_root_dev_deps_with_testing {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
 
-    assert_that(
-      cargo::util::process(p.bin("foo")),
-      execs().with_stdout("zoidberg\n"));
+            name = "foo"
+            version = "0.5.0"
+            authors = ["wycats@example.com"]
+
+            [dev-dependencies.bar]
+
+            version = "0.5.0"
+            path = "../bar"
+
+            [[bin]]
+            name = "foo"
+        "#)
+        .file("src/main.rs",
+              main_file(r#""{}", bar::gimme()"#, ["bar"]).as_slice());
+    let p2 = project("bar")
+        .file("Cargo.toml", r#"
+            [package]
+
+            name = "bar"
+            version = "0.5.0"
+            authors = ["wycats@example.com"]
+        "#)
+        .file("src/lib.rs", r#"
+            pub fn gimme() -> &'static str {
+                "zoidberg"
+            }
+        "#);
+
+    p2.build();
+    assert_that(p.cargo_process("cargo-test"),
+        execs().with_stdout(format!("\
+{compiling} bar v0.5.0 ({url})
+{compiling} foo v0.5.0 ({url})
+{running} target[..]test[..]foo-[..]
+
+running 0 tests
+
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
+
+", compiling = COMPILING, url = p.url(), running = RUNNING)));
 })
 
 test!(cargo_compile_with_transitive_dev_deps {